// 引入当前页面的less文件 
require("../less/index.less")
// 引入字体图标
require("../fonts/iconfont.css");
document.ready(function () {
    // 获取元素
    // 轮播图
    const slideshowUl = document.querySelector(".slideshow-ul");
    let arrslideshow = ["../img/part1.png", "../img/part2.png", "../img/part3.png"];
    for (let i = 0; i < arrslideshow.length; i++) {
        slideshowUl.innerHTML += `
            <li><img src="${arrslideshow[i]}" alt=""></li>
        `
    }
    const slideshowUlImg = document.querySelectorAll(".slideshow-ul li img");
    let re = 0;
    slideshowUlImg[0].style.display = "block";
    setInterval(function () {
        for (let i = 0; i < slideshowUlImg.length; i++) {
            slideshowUlImg[i].style.display = "none";
        }
        slideshowUlImg[re].style.display = "block";
        re++;
        if (re == 3) { re = 0 }
    }, 1000)

    // 获取元素
    //设置请求头部的token
    let user = JSON.parse(localStorage.getItem("user"));

        console.log("aaa",user)
    axios.post("http://139.9.177.51:3701/api/user/login", {
    "account":user.account, "password":user.password
    }).then(function (res) {
      let re = res.data;
       if (res.data.errno == 0) {
            // let rse = JSON.stringify(re);
            //  console.log(re.data.token)
             console.log("bbb",re);
             user=re.data;
             console.log(user.token);
          }
    }).catch((err) => {
        console.log(err);
   })



    axios.defaults.headers.authorization = `Bearer ${user.token}`;
    //发送请求获取当前用户数据
    axios.get("http://139.9.177.51:3701/api/user/info")
        .then((res) => {
            let result = res.data;
            console.log(result);
            if (result.errno === 0) {//获取成功
                //排名
                rankNum.textContent = result.data.ranking;
                //累积打卡天数  此处一定要使用[]来取属性                  
                clockDay.textContent = result.data["member.clockCount"];
                //徽章
                badgeNum.textContent = result.data.badges
            } else if (result.errno === 10003) {//未登录
                window.$util.toast("zp-close", "请先登录");
                window.setTimeout(() => {
                    window.location.href = "./login.html"
                }, 3001)
            }
        })
        .catch((err) => {
            console.log(err);
        })








});